package com.gofunbuy.app.others;

import com.gofunbuy.MainActivity;
import com.gofunbuy.R;
import com.gofunbuy.TabMemberGroup;
import com.gofunbuy.TabOthersGroup;
import com.gofunbuy.app.home.HomeActivity;
import com.gofunbuy.app.home.TabAboutActivity;
import com.gofunbuy.app.member.SubMemberDocumentActivity;
import com.gofunbuy.app.member.SubMemberIntegrationActivity;
import com.gofunbuy.app.member.SubMemberPayHistoryActivity;
import com.gofunbuy.app.member.TabMemberActivity;
import com.gofunbuy.util.GoFunBuyUtils.GoFunBuyInterface;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class TabOthersActivity extends Activity implements OnClickListener,
		GoFunBuyInterface {
	private TextView tvTitle;
	private TextView tvBack;
	private RelativeLayout linearLayoutAbout, linearLayoutShare,
			linearLayoutSetup, linearLayoutReceipt, linearLayoutShopingHistory,
			linearLayoutDocSetup, linearLayoutInteration;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.others_layout);
		initLayout();
	}

	private void initLayout() {
		tvTitle = (TextView) findViewById(R.id.topbar_title);
		tvTitle.setText(R.string.title_other);
		tvBack = (TextView) findViewById(R.id.topbar_back);
		tvBack.setOnClickListener(this);
		tvBack.setVisibility(View.INVISIBLE);
		linearLayoutAbout = (RelativeLayout) findViewById(R.id.other_about);
		linearLayoutAbout.setOnClickListener(this);
		linearLayoutShare = (RelativeLayout) findViewById(R.id.other_share);
		linearLayoutShare.setOnClickListener(this);
		linearLayoutSetup = (RelativeLayout) findViewById(R.id.other_doc_setup);
		linearLayoutSetup.setOnClickListener(this);
		linearLayoutReceipt = (RelativeLayout) findViewById(R.id.other_setup);
		linearLayoutReceipt.setOnClickListener(this);
		linearLayoutShopingHistory = (RelativeLayout) findViewById(R.id.other_receipt);
		linearLayoutShopingHistory.setOnClickListener(this);
		linearLayoutDocSetup = (RelativeLayout) findViewById(R.id.other_interation);
		linearLayoutDocSetup.setOnClickListener(this);
		linearLayoutInteration = (RelativeLayout) findViewById(R.id.other_shopping_history);
		linearLayoutInteration.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.topbar_back:
			// startActivity(TabMemberActivity.class);
			break;
		case R.id.other_about:
			// startExactTabActivity(TAB_HOME);
			startActivity(TabAboutActivity.class);
			break;
		case R.id.other_share:
			// startActivity(SubMemberIntegrationActivity.class);
			break;
		case R.id.other_doc_setup:
			// startActivity(SubMemberPayHistoryActivity.class);
			break;

		case R.id.other_setup:
			// startActivity(SubMemberPayHistoryActivity.class);
			break;

		case R.id.other_receipt:
			// startActivity(SubMemberPayHistoryActivity.class);
			break;

		case R.id.other_interation:
			startActivity(SubMemberIntegrationActivity.class);
			break;
		case R.id.other_shopping_history:
			startActivity(SubMemberPayHistoryActivity.class);
			break;
		}
	}

	private void startActivity(Class<?> a) {
		// 要跳转的Activity
		// Log.v("名字", a.getSimpleName() + " " + a.getName());
		Intent intent = new Intent(this, a);
		intent.putExtra(BACK_TO_WHO, 5);
		// 把Activity转换成一个Window，然后转换成View
		Window w = TabOthersGroup.group.getLocalActivityManager()
				.startActivity(a.getSimpleName(), intent);
		View view = w.getDecorView();
		// 设置要跳转的Activity显示为本ActivityGroup的内容
		TabOthersGroup.group.setContentView(view);
	}

	private void startExactTabActivity(int pose) {
		Intent it = new Intent(this, MainActivity.class);
		it.putExtra(TAB_POSE, pose);
		if (pose != 0)
			it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(it);
		finish();
	}
}
